package com.ysjweb.dish.tool;

import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.Map;

@Component
public class JwtTool {
    public static String generateJwt(Map<String,Object> claims) {
        String jwt = Jwts.builder()
                .signWith(SignatureAlgorithm.HS256,"Dish")
                .setClaims(claims)
                .setExpiration(new Date(System.currentTimeMillis() + 43200000L))
                .compact();
        return jwt;
    }
    public static Claims parseJwt(String jwt) {
        Claims claims = Jwts.parser()
                .setSigningKey("Dish")
                .parseClaimsJws(jwt)
                .getBody();
        return claims;
    }
}
